home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-15 | 6.3 KB | 245 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CTridentView.cp ©1993 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
-
- #include "CTridentWindow.h"
- #include "CTridentApp.h"
- #include "CTridentCmds.h"
- #include "CTridentIdler.h"
- #include "TridentAESuite.h"
- #include <LStream.h>
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
- //==============================window stuff====================================
-
- CTridentWindow*
- CTridentWindow::CreateTridentWindowStream(
- LStream *inStream)
- {
- return (new CTridentWindow(inStream));
- }
-
- CTridentWindow::~CTridentWindow()
- {
-
- if (mSuperCommander != NULL)
- {
- if (this->IsConnected())
- this->SendQuit();
- // ((CTridentApp*)mSuperCommander)->CloseWindow(this->mPaneID);
- fAEAddressDesc.dataHandle = NULL; //eventually want to send a AEQuit!
- }
- }
- CTridentWindow::CTridentWindow(
- LStream *inStream)
- : LWindow(inStream)
- {
- fAEAddressDesc.descriptorType = typeNull;
- fAEAddressDesc.dataHandle = NULL;
- }
- void CTridentWindow::SetPortRefNum(short thePortRefNum)
- {
- fPortRefNum = thePortRefNum;
- }
-
- void CTridentWindow::Connect()
- {
- MyBrowser((CTridentWindow*) this);
- if (this->IsConnected())
- this->SendNull();
- if (this->IsConnected())
- this->SendVersion();
-
- if (myView != NULL)
- if (myView->fHeartBeatMonitor != NULL)
- myView->fHeartBeatMonitor->StartIdling();
-
- }
-
- void CTridentWindow::SendNull()
- {
- long clientSessionID = (long) this->fPortRefNum;
- AEAddressDesc& theAddress = this->fAEAddressDesc;
- AppleEvent appleEvent, replyEvent;
- OSErr err = AECreateAppleEvent(kAEAUXSuite, kAENull, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &appleEvent);
- err = AECreateDesc(typeNull, NULL, 0, &replyEvent);
- err = AEPutParamPtr(&appleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));
- UAppleEventsMgr::SendAppleEventWithReply(appleEvent,replyEvent, TRUE);
- AEDisposeDesc(&replyEvent);
- AEDisposeDesc(&appleEvent);
- }
-
- void CTridentWindow::SendQuit()
- {
- long clientSessionID = (long) this->fPortRefNum;
- AEAddressDesc& theAddress = this->fAEAddressDesc;
- AppleEvent appleEvent , replyEvent;
-
- // if (::Alert(1000, 0) != 2)
- // {
- OSErr err = ::AECreateAppleEvent(kAEAUXSuite, kAEQuit, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &appleEvent);
- err = AEPutParamPtr(&appleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));
- err = ::AECreateDesc(typeNull, NULL, 0, &replyEvent);
-
- err = ::AESend(&appleEvent, &replyEvent, kAENoReply | kAEDontReconnect, kAENormalPriority, kAEDefaultTimeout, nil, nil);
- // }
- AEDisposeDesc(&appleEvent);
- AEDisposeDesc(&replyEvent);
- }
-
- void CTridentWindow::SendVersion()
- {
- OSErr err;
- AppleEvent versionappleEvent, reply2Event;
- DescType actualCode;
- long actualSize;
- long clientSessionID = (long) this->fPortRefNum;
- AEAddressDesc& theAddress = this->fAEAddressDesc;
- OSType myVersion = '6.66'; //the version from hell
- Handle initialVersionH = ::Get1Resource('rDrD', 128);
- // if (::Alert(1001, 0) != 2)
- // {
- if (initialVersionH != nil)
- ::BlockMove(*initialVersionH, &myVersion, 4);
- // }
- err = AECreateAppleEvent(kAEAUXSuite, kAEVersion, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &versionappleEvent);
- err = ::AEPutParamPtr(&versionappleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));
- err = ::AECreateDesc(typeNull, NULL, 0, &reply2Event);
- err = ::AEPutParamPtr(&versionappleEvent, keyAEVersion, typeChar, &myVersion, sizeof(OSType));
-
- err = ::AESend(&versionappleEvent, &reply2Event, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, nil, nil);
-
- LStr255 theText;
-
- char status[1];
- if (&reply2Event != nil) {
- err = ::AEGetParamPtr(&reply2Event, keyErrorNumber, typeChar, &actualCode, (Ptr)status, sizeof(char), &actualSize);
- if (*status == 'S')
- {
- CTridentView* myListBox = (CTridentView*) this->FindPaneByID('winb');
-
- theText = "It is alive";
- if (myListBox != NULL)
- myListBox->SetDescriptor(theText);
- myView = myListBox;
- }
- AEDisposeDesc(&reply2Event);
- }
- AEDisposeDesc(&versionappleEvent);
-
- }
- Boolean
- CTridentWindow::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- case 421:
- this->SendInterval(10);
- break;
- case 422:
- this->SendInterval(30);
- break;
- case 423:
- this->SendInterval(60);
- break;
- case 424:
- this->SendInterval(600);
- break;
- case 425:
- this->SendInterval(3600);
- break;
-
- default:
- cmdHandled = inherited::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- void CTridentWindow::SendInterval(long seconds)
- {
- if (myView != NULL)
- myView->SendInterval(seconds);
- }
-
- void CTridentWindow::SendHeart()
- {
- if (this->IsConnected())
- {
- long clientSessionID = (long) this->fPortRefNum;
- AEAddressDesc& theAddress = this->fAEAddressDesc;
-
- AppleEvent heartappleEvent;
- OSErr err = AECreateAppleEvent(kAEAUXSuite, kAEHeartBeat, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &heartappleEvent);
- err = ::AEPutParamPtr(&heartappleEvent, 'ssID',typeLongInteger,(Ptr)&clientSessionID,sizeof(long));
- UAppleEventsMgr::SendAppleEvent(heartappleEvent, TRUE);
- if (myView != NULL)
- myView->ResetTicks();
- }
- }
-
- Boolean CTridentWindow::IsConnected()
- {
- return (fAEAddressDesc.dataHandle != NULL);
- }
-
-
- void CTridentWindow::SetAddress(TargetID& theTarget)
- {
- // Accepts result of PPCBrowser call. May fail.
-
- AEAddressDesc targetAddress;
-
- ThrowIfOSErr_(AECreateDesc(typeTargetID, Ptr(&theTarget), sizeof(theTarget),
- &targetAddress));
- fAEAddressDesc = targetAddress;
- }
-
- void
- CTridentWindow::HandleAppleEvent(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult,
- long inAENumber)
- {
- if (myView != NULL)
- {
- myView->ResetTicks();
- myView->HandleAppleEvent(inAppleEvent, outAEReply,
- outResult, inAENumber);
- }
- }
- void
- CTridentWindow::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
- case 421:
- case 422:
- case 423:
- case 424:
- case 425:
- if (myView != NULL)
- myView->FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- default:
- inherited::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- }
- }
-
-